package com.awphone.data;

import com.awphone.data.constant.EObjectType;
import com.awphone.data.constant.UserConst;

import javax.persistence.*;
import java.util.Date;

/**
 * @author a_polyakov
 * Date: 05.03.13
 * Time: 1:54
 * Пользователь
 */
@Entity
@Table(schema = UserConst.SCHEMA_NAME, name = UserConst.TABLE_NAME)
public class User extends AbstractObject {
    /**
     * Псевдоним
     */
    private String username;
    /**
     * Адрес электронной почты
     */
    private String email;
    /**
     * Пароль
     */
    private String password;
    /**
     * Уведомлять об ответе на комментарий
     */
    private Boolean sendEmailToResponseComment;
    /**
     * Признак пользователя созданного автоматически
     */
    private Boolean isBot;
    /**
     * Дата регистрации
     */
    private Date created;

    {
        setObjectType(EObjectType.USER);
    }

    public User() {
    }

    public User(String username, String email, String password, Boolean sendEmailToResponseComment, Boolean bot) {
        this.username = username;
        this.email = email;
        this.password = password;
        this.sendEmailToResponseComment = sendEmailToResponseComment;
        isBot = bot;
    }

    @Column(name = UserConst.S_USERNAME, nullable = false, unique = true, updatable = false)
    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    @Column(name = UserConst.S_EMAIL, nullable = false, unique = true, updatable = false)
    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    @Column(name = UserConst.S_PASSWORD, nullable = true, unique = false, updatable = true)
    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    @Column(name = UserConst.S_SEND_EMAIL_TO_RESPONSE_COMMENT, nullable = false, unique = false, updatable = true)
    public Boolean getSendEmailToResponseComment() {
        return sendEmailToResponseComment;
    }

    public void setSendEmailToResponseComment(Boolean sendEmailToResponseComment) {
        this.sendEmailToResponseComment = sendEmailToResponseComment;
    }

    @Column(name = UserConst.S_IS_BOT, nullable = false, unique = false, updatable = false)
    public Boolean getIsBot() {
        return isBot;
    }

    public void setIsBot(Boolean isBot) {
        this.isBot = isBot;
    }

    @Column(name = UserConst.S_CREATED, nullable = false, unique = false, updatable = false)
    @Temporal(TemporalType.TIMESTAMP)
    public Date getCreated() {
        return created;
    }

    public void setCreated(Date created) {
        this.created = created;
    }

    @Override
    public void prePrePersist() {
        super.prePrePersist();
        this.created=new Date();
    }
}
